package com.bee.study.serice;


import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * 测试LoadingCache的使用
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2020-9-26
 */
public class LoadingCacheTest {

    private static LoadingCache<String,Object> loadingCache = CacheBuilder.newBuilder()
            .maximumSize(1000)
            .expireAfterWrite(3, TimeUnit.SECONDS)
            .build(new CacheLoader<String, Object>() {
                @Override
                public Object load(String s) throws Exception {
                    System.out.println(s);
                    return testLoadingCache();
                }
            });

    public static void main(String[] args) throws ExecutionException {
        loadingCache.put("ss","ee");
        System.out.println(loadingCache.get("dd"));

    }

    public static String testLoadingCache(){
        return "aa";
    }
}
